Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

138
Views
Estoy tratando de asignar un valor para index[arr[i][j]]['x'], obtengo el mensaje No se puede establecer la propiedad 'x' de un error indefinido

Aquí está mi código para referencia. Recibo un error para las líneas 9 y 10. ¿Hay alguna forma de asignar valores para el diccionario dentro de un diccionario inicialmente vacío?

 function anticlockwiseRotate(arr){ //store the index of elements in a dict let index={}; for(let i=0;i<3;i++){ for(let j=0;j<3;j++){ if(!index.hasOwnProperty(arr[i][j]['x']) && !index.hasOwnProperty(arr[i][j]['y'])){ //left shift by 2 and change rowInde) //left shift by 2 and change rowIndex->columnIndex index[arr[i][j]]['x'] = (Math.abs(j-2)); index[arr[i][j]]['y']=i; } } } let rotatedArr= []; for(let idx in index){ rotatedArr[index[idx][x]][index[idx][y]]=idx; } return rotatedArr } console.log(anticlockwiseRotate([[1,2,3],[4,5,6],[7,8,9]]))
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

establezca index[arr[i][j]] como objeto antes de asignar cualquier propiedad a index[arr[i][j]]

 index[arr[i][j]] = {}; //left shift by 2 and change rowInde) //left shift by 2 and change rowIndex->columnIndex index[arr[i][j]]['x'] = (Math.abs(j-2)); index[arr[i][j]]['y']=i;
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!